﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.Networking;
using ig.app.Services.ig.app.Services;
using Xamarin.Forms;

[assembly: Dependency(typeof(ig.app.UWP.DependencyServices.IPAddressManager))]
namespace ig.app.UWP.DependencyServices
{


    class IPAddressManager : IIPAddressManager
    {
        public async Task<string[]> GetIPAddress()
        {
            try
            {
                List<string> IpAddress = new List<string>();
                var Hosts = Windows.Networking.Connectivity.NetworkInformation.GetHostNames().ToList();
                foreach (var Host in Hosts)
                {
                    string ip = Host.DisplayName;
                    if (Host.Type == HostNameType.Ipv4)
                        IpAddress.Add(ip);
                }

                return IpAddress.ToArray();
                //IPAddress address = IPAddress.Parse(IpAddress.Last());
                //return address.ToString();
            }
            catch (Exception ex)
            {
                return null;
            }
        }


        public async Task<string[]> GetLocalServer()
        {
            throw new NotImplementedException();
        }

 
    }
}
